<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/vendor/bootstrap/css/bootstrap.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/vendor/font-awesome/css/font-awesome.min.css">
    <!-- Custom Font Icons CSS-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/font.css">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/custom.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/layer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/bootstrap/css/bootstrap-switch.min.css">
    <title>查看用户</title>
</head>
<body>
<%@include file="header.jsp"%>
<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <%@include file="nav.jsp"%>
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">用户列表</h2>
            </div>
        </div>
        <section class="no-padding-bottom">
            <div class="title">
                <form class="form-inline" action="${pageContext.request.contextPath}/user/userList" method="post">
                    <div class="form-group">
                        <label for="inlineFormInput" class="sr-only">Name</label>
                        <input id="inlineFormInput" type="text" placeholder="按名字查找" class="mr-sm-3 form-control" name="name">
                    </div>
                    <div class="form-group">
                        <input type="submit" value="查询" class="btn btn-primary">
                    </div>
                </form>

            </div>
            <div class="table-responsive">
                <table class="table">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>简介</th>
                        <th>操作</th>
                        <th>加关注</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach var="user" items="${usersByPage}">
                        <tr>
                            <td scope="row">${user.user_id}</td>
                            <td>${user.real_name}</td>
                            <td>
                                <c:if test="${user.gender == 0}">
                                    女
                                </c:if>
                                <c:if test="${user.gender == 1}">
                                    男
                                </c:if>
                            </td>
                            <td>${user.age}</td>
                            <td>${user.interduce}</td>
                            <td>
                                <input type="submit" value="详细信息" class="btn-xs btn-primary userDetail" onclick="showDetail(${user.user_id})">
                            </td>
                            <td>
                                <c:if test="${user.fid == null}">
                                    <input type="checkbox" value="" class="checkbox-template" onclick="changeFocus(this,${user.user_id})">
                                </c:if>
                                <c:if test="${user.fid != null}">
                                    <input type="checkbox" value="" class="checkbox-template" onclick="changeFocus(this,${user.user_id})" checked>
                                </c:if>
                            </td>
                        </tr>
                    </c:forEach>

                    </tbody>
                </table>

                <nav class="text-center" aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a href="#" aria-label="Previous" onclick="last()">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach begin="${startPage}" end="${endPage}" var="i">
                            <c:if test="${i == currentPage}">
                                <li><a href="#" class="act" onclick="toPage(${i})">${i}</a></li>
                            </c:if>
                            <c:if test="${i != currentPage}">
                                <li><a href="#" onclick="toPage(${i})">${i}</a></li>
                            </c:if>
                        </c:forEach>
                        <li>
                            <a href="#" aria-label="Next" onclick="next()">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </section>

        <footer class="footer">
            <div class="footer__block block no-margin-bottom">
                <div class="container-fluid text-center">
                    <p class="no-margin-bottom">Copyright &copy; 2019.Company <a href="#" >东方标准</a> </p>
                </div>
            </div>
        </footer>
    </div>
</div>

<!-- JavaScript files-->
<script src="${pageContext.request.contextPath}/assets/vendor/jquery/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/vendor/popper.js/umd/popper.min.js"> </script>
<script src="${pageContext.request.contextPath}/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/bootstrap/js/bootstrap-switch.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/vendor/jquery.cookie/jquery.cookie.js"> </script>
<script src="${pageContext.request.contextPath}/assets/vendor/chart.js/Chart.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/layer.js"></script>
<script src="${pageContext.request.contextPath}/assets/vendor/jquery-validation/jquery.validate.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/charts-home.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/front.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/custom.js"></script>


<script>
    function toPage(page){
        location.href = '${pageContext.request.contextPath}/user/userList?currentPage=' + page + "&name=${name}";
    }
    function last() {
        var count = ${currentPage - pageCount};
        if(count > 0){
            location.href = '${pageContext.request.contextPath}/user/userList?currentPage=${currentPage - pageCount}&name=${name}';
        }else{
            location.reload();
            alert("没有上一轮了！");
        }

    }
    function next() {
        var totalPage = ${totalPage};
        var count = ${currentPage + pageCount};
        if(!(count > totalPage)){
            location.href = '${pageContext.request.contextPath}/user/userList?currentPage=${currentPage + pageCount}&name=${name}';
        }else{
            location.reload();
            alert('没有下一轮了！');
        }
    }

    function changeFocus(obj,fuid) {
        var flag = $(obj).prop("checked");
        if(flag){
            $.post('${pageContext.request.contextPath}/user/onFocus',{fuid : fuid},function (data) {
                if('1' == data){
                    alert('关注成功！');
                }else{
                    alert(data);
                    var flag = $(obj).prop("checked",false);
                }
            });
        }else{
            $.post('${pageContext.request.contextPath}/user/offFocus',{fuid : fuid},function (data) {
                if('1' == data){
                    alert('取关成功！');
                }else{
                    alert(data);
                    var flag = $(obj).prop("checked",true);
                }
            });
        }
    }

    function showDetail(uid){
        location.href = '${pageContext.request.contextPath}/user/showUserDetail?uid=' + uid;
    }
</script>
</body>
</html>
